package com.our.biz;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.our.dao.NewsMapper;
import com.our.dao.RepResourceMapper;
import com.our.model.News;

@Service
public class NewsBiz {
	@Resource
	private NewsMapper dao;
	@Resource
	private RepResourceMapper resdao;
	
	
	public List<News> findAll(){
		return dao.selectAll();
	}
	
	public News findById(int newsId){
		return dao.selectByPrimaryKey(newsId);
	}

	public void delete(int newsId) {
		dao.deleteByPrimaryKey(newsId);	
	}
	
	public void save(News news){
		news.setCreateTime(new Date());
		dao.insert(news);
	}
	
	public void update(News news){
		if(news.getRes()!=null){
			resdao.insert(news.getRes());
		}
		news.setUpdateTime(new Date());
		dao.updateByPrimaryKeySelective(news);
	}

	public List<News> findByTypeId(int typeId) {
		List<News> list =  dao.selectByTypeId(typeId);
		for(News news:list){
			System.out.println(news);
		}
		return list;
		
	}

}
